using Assets.Scripts.GDK;
using UnityEngine;


namespace Brick
{
	public class ZhangAiWu : gdk_base_UI
	{
		private int effectHitNum = 1;

		public itemMake itemMakeObj;

		private GameObject openObject;

		private GameObject closeObject;

		private GameObject dizhenGO;

		private Bomb myBomb;

		private LockLock curLock;

		private bool isRecive;

		public override void OnStart()
		{
			itemMakeObj = base.gameObject.GetComponent<itemMake>();
			myBomb = base.gameObject.GetComponent<Bomb>();
			curLock = base.gameObject.GetComponent<LockLock>();
			isRecive = false;
		}

		public void OnReciev()
		{
			isRecive = false;
		}

		public bool GetRecive()
		{
			return isRecive;
		}

		public void OnCollisionEnter2D(Collision2D c)
		{
			OnHitCount(1);
		}

		public void OnTriggerEnter2D(Collider2D other)
		{
			OnHitCount(1);
		}

		public void setNum(int count)
		{
			if ((bool)itemMakeObj)
			{
				itemMakeObj.setNum(count);
			}
		}

		public void OnBomb()
		{
			itemMakeObj = base.gameObject.GetComponent<itemMake>();
			OnHitCount(itemMakeObj.num);
		}

		public void OnHitOnce()
		{
			OnHitCount(1);
		}

		public void OnHitMore(int count)
		{
			OnHitCount(count);
		}

		public void OnHitTweenty()
		{
			itemMakeObj = base.gameObject.GetComponent<itemMake>();
			int count = itemMakeObj.num / 3 + 1;
			OnHitMore(count);
			if (dizhenGO == null)
			{
				dizhenGO = AddOpenClose("dizhendaoju");
			}
			else
			{
				dizhenGO.GetComponentInChildren<ParticleSystem>().Play();
			}
		}

		public void checkBomb()
		{
			if ((bool)myBomb)
			{
				myBomb.OnBomb();
			}
		}

		public int getType()
		{
			return GDK.ModuleManger.Module<BallBoxModule>().getTestType();
		}

		private void OnHitCount(int count)
		{
			gdk_game_manager.PlayHitSound();
			itemMakeObj = base.gameObject.GetComponent<itemMake>();
			int num = effectHitNum;
			if ((bool)curLock)
			{
				if (!curLock.GetOpen())
				{
					return;
				}
				if (!curLock.GetZheng())
				{
					num = -num;
				}
			}
			int num2 = itemMakeObj.num - num * count;
			if (num2 < 0)
			{
				num2 = 0;
			}
			setNum(num2);
			if (itemMakeObj.num < 1)
			{
				checkBomb();
				cleanItem();
				gdk_game_manager.DispachEvent(EventID.GAME_SCORE_ADD);
			}
		}

		public void cleanItem()
		{
			if (!isRecive)
			{
				isRecive = true;
				AddAnimator();
				if (base.gameObject != null)
				{
					EnemyPool.GetInstance().RecycleObj(base.gameObject);
				}
			}
			UnityEngine.Object.Destroy(base.gameObject);
		}

		public void AddAnimator()
		{
			if (itemMakeObj.type == 1 && itemMakeObj.typeID == 1)
			{
				AddSui("sanjiao_suikuai01");
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 2)
			{
				AddSui("sanjiao_suikuai04");
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 3)
			{
				AddSui("sanjiao_suikuai02");
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 4)
			{
				AddSui("sanjiao_suikuai03");
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 9)
			{
				AddSui("zhadanbaozha");
			}
			else
			{
				AddSui("fangkuai");
			}
		}

		public void SetEffectTwo()
		{
			effectHitNum = 2;
		}

		public void ResetEffect()
		{
			effectHitNum = 1;
		}

		public GameObject AddSui(string filename)
		{
			string pathName = "Prefabs/effect/" + filename;
			GameObject item = EnemyPool.GetInstance().GetObj(filename, pathName);
			UnityEngine.Debug.Log(item);
			if ((bool)item)
			{
				item.SetActive(value: true);
				item.transform.SetParent(base.transform.parent.transform);
				item.transform.localScale = Vector3.one;
				item.transform.localPosition = base.transform.localPosition;
				gdk_runTime.setTimeOut(delegate
				{
					gdk_game_manager.log("回收资源!");
					if (item != null)
					{
						EnemyPool.GetInstance().RecycleObj(item);
					}
				}, 2f, item);
			}
			return item;
		}

		public GameObject AddOpenClose(string filename)
		{
			string id = "Prefabs/effect/" + filename;
			GameObject gameObject = gdk_game_manager.loadPrefab(id);
			if ((bool)gameObject)
			{
				gameObject.transform.SetParent(base.transform);
				gameObject.transform.localScale = Vector3.one;
				gameObject.transform.localPosition = Vector3.zero;
			}
			return gameObject;
		}

		public void OpenState()
		{
			itemMakeObj = base.gameObject.GetComponent<itemMake>();
			if (itemMakeObj.type == 1 && itemMakeObj.typeID == 5)
			{
				if ((bool)openObject)
				{
					KaiheAnim component = openObject.GetComponent<KaiheAnim>();
					component.OpenAnim();
				}
				else
				{
					openObject = AddOpenClose("KaiheAnimator");
					KaiheAnim component2 = openObject.GetComponent<KaiheAnim>();
					component2.OpenAnim();
				}
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 7)
			{
				itemMakeObj.OpenState();
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 10 && !openObject)
			{
				openObject = AddOpenClose("tanqiu_men02_zhang");
			}
		}

		public void CloseState()
		{
			itemMakeObj = base.gameObject.GetComponent<itemMake>();
			if (itemMakeObj.type == 1 && itemMakeObj.typeID == 5)
			{
				if ((bool)openObject)
				{
					KaiheAnim component = openObject.GetComponent<KaiheAnim>();
					component.CloseAnim();
				}
				else
				{
					openObject = AddOpenClose("KaiheAnimator");
					KaiheAnim component2 = openObject.GetComponent<KaiheAnim>();
					component2.CloseAnim();
				}
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 7)
			{
				itemMakeObj.CloseState();
			}
			else if (itemMakeObj.type == 1 && itemMakeObj.typeID == 10 && !closeObject)
			{
				closeObject = AddOpenClose("tanqiu_men02_he");
			}
		}
	}
}

